home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Milan_1991 / Devcon91.4 / AppShell / Examples / Support / objectio.c < prev   
Encoding:
C/C++ Source or Header  |  1992-09-01  |  41.1 KB  |  1,740 lines

  1. /************************************************************************
  2.  *                                                                      *
  3.  *                            Preliminary                               *
  4.  *                        Amiga AppShell (tm)                           *
  5.  *                                                                      *
  6.  *  Copyright (c) 1990,1991 Commodore-Amiga, Inc. All Rights Reserved.  *
  7.  *                                                                      *
  8.  *   This software and information is proprietary, preliminary, and     *
  9.  *   subject to change without notice.                                  *
  10.  *                                                                      *
  11.  *                            DISCLAIMER                                *
  12.  *                                                                      *
  13.  *   THIS SOFTWARE IS PROVIDED "AS IS".                                 *
  14.  *   NO REPRESENTATIONS OR WARRANTIES ARE MADE WITH RESPECT TO THE      *
  15.  *   ACCURACY, RELIABILITY, PERFORMANCE, CURRENTNESS, OR OPERATION      *
  16.  *   OF THIS SOFTWARE, AND ALL USE IS AT YOUR OWN RISK.                 *
  17.  *   NEITHER COMMODORE NOR THE AUTHORS ASSUME ANY RESPONSIBILITY OR     *
  18.  *   LIABILITY WHATSOEVER WITH RESPECT TO YOUR USE OF THIS SOFTWARE.    *
  19.  *                                                                      *
  20.  *                          Non-Disclosure                              *
  21.  *                                                                      *
  22.  *   This information is not to be disclosed to any other company,      *
  23.  *   individual or party.  Discussion is to be restricted to CBM        *
  24.  *   approved discussion areas, such as the closed conferences on bix;  *
  25.  *   amiga.cert, amiga.com, amiga.beta/appshell.                        *
  26.  *                                                                      *
  27.  ************************************************************************
  28.  * ObjectIO.c
  29.  * Copyright (C) 1990 Commodore-Amiga, Inc.
  30.  * written by David N. Junod
  31.  *
  32.  */
  33.  
  34. #define    SKIP_IPROTOS        TRUE
  35. #define    CLIB_APPSHELL_IPROTOS_H    TRUE
  36.  
  37. #include <exec/types.h>
  38. #include <intuition/icclass.h>
  39. #include <libraries/asl.h>
  40. #include "ae:support/misc_protos.h"
  41. #include <internal/appshell_internal.h>
  42. #include <libraries/appshell.h>
  43. #include <libraries/appobjects.h>
  44. #include <libraries/gadtools.h>
  45. #include <clib/macros.h>
  46. #include <clib/appshell_protos.h>
  47. #include <clib/appobjects_protos.h>
  48. #include <clib/asl_protos.h>
  49. #include <pragmas/appshell_pragmas.h>
  50. #include <pragmas/appobjects_pragmas.h>
  51. #include <pragmas/asl_pragmas.h>
  52.  
  53. struct FuncsNode
  54. {
  55.     struct Node fn_Node;
  56.     struct Funcs fn_Func;
  57.     struct ObjectNode *fn_Obj;
  58. };
  59.  
  60. struct GetRec
  61. {
  62.     ULONG *gr_BaseName;
  63. };
  64.  
  65. struct DumpRec
  66. {
  67.     struct ObjectInfo *dr_OI;    /* ObjectInfo */
  68.     BPTR dr_FH;            /* File handle to write to */
  69.     STRPTR dr_BaseName;        /* Pointer to the environment base name */
  70. };
  71.  
  72. struct PrintRec
  73. {
  74.     BPTR pr_FH;
  75. };
  76.  
  77. static LONG fprint (BPTR fh, UBYTE *format, VOID *data,...)
  78. {
  79.     LONG VFPrintf (BPTR fh, UBYTE * format, LONG * argarray);
  80.  
  81.     return (VFPrintf (fh, format, (ULONG *) & data));
  82. }
  83.  
  84. /* ObjectIO.c */
  85. static VOID MakeHeader (BPTR fh, STRPTR name, STRPTR filename);
  86. static VOID findbase (struct ObjectNode * on, ULONG cnt, struct GetRec * gr);
  87. static VOID dumpfcid (struct FuncsNode * fn, ULONG cnt, struct DumpRec * dr);
  88. static VOID dumpproto (struct FuncsNode * fn, ULONG cnt, struct DumpRec * dr);
  89. static VOID dumpfunc (struct FuncsNode * fn, ULONG cnt, struct DumpRec * dr);
  90. static VOID makefunc (struct FuncsNode * fn, ULONG cnt, struct DumpRec * dr);
  91. static VOID makeappdata (struct FuncsNode * fn, ULONG cnt, struct DumpRec * dr);
  92. static VOID dumptext (struct ObjectNode * on, ULONG cnt, struct DumpRec * dr);
  93. static VOID ImageToC (BPTR fh, STRPTR name, struct Image * i);
  94. static VOID dumplist (struct Node * n, ULONG cnt, struct PrintRec * pr);
  95. static VOID printtagdata (BPTR fh, STRPTR name, ULONG t, struct TagItem * tl);
  96. static VOID printFlags (BPTR fh, UBYTE * name, SHORT lvl, UBYTE * pref);
  97. static VOID parseFlags (BPTR fh, ULONG flags, struct ulongFlags * uf, UBYTE * pref, UBYTE * sufx);
  98. static VOID printtags (BPTR fh, STRPTR name, ULONG t, struct TagItem * tl);
  99. static VOID dumptagdata (struct ObjectNode * on, ULONG cnt, struct DumpRec * dr);
  100. static VOID dumptags (struct ObjectNode * on, ULONG cnt, struct DumpRec * dr);
  101. static VOID dumpobject (struct ObjectNode * on, ULONG cnt, struct DumpRec * dr);
  102. VOID SaveObjectList (struct AppInfo * ai, STRPTR cmd, struct TagItem * attrs);
  103.  
  104. #define    FILL "/**********************************************************************/\n"
  105.  
  106. VOID
  107. SaveObjectList (struct AppInfo * ai, STRPTR cmd, struct TagItem * attrs)
  108. {
  109.     struct ObjectInfo *oi = NULL;
  110.     STRPTR filename = "RAM:test.c";
  111.     STRPTR name = NULL;
  112.  
  113.     if (attrs)
  114.     {
  115.     struct Window *win = NULL;
  116.  
  117.     if (win = (struct Window *) GetTagData (APSH_WinPointer, NULL, attrs))
  118.     {
  119.         oi = (struct ObjectInfo *) win->UserData;
  120.     }
  121.     else if (name = (STRPTR)
  122.          GetTagData (APSH_WinName, (ULONG) "Main", attrs))
  123.     {
  124.         struct MHObject *mho;
  125.         struct WinNode *wn;
  126.  
  127.         /* get a pointer to the message handler data */
  128.         if (mho = HandlerData (ai, APSH_Handler, "IDCMP", TAG_DONE))
  129.         {
  130.         /* get a pointer on the data */
  131.         if (wn = (struct WinNode *) FindNameI (&(mho->mho_ObjList), name))
  132.         {
  133.             oi = wn->wn_OI;
  134.         }
  135.         }
  136.     }
  137.  
  138.     /* Get the file name to save to */
  139.     filename = (STRPTR) GetTagData (APSH_NameTag, (ULONG) filename, attrs);
  140.     }
  141.  
  142.     if (oi)
  143.     {
  144.     BPTR fh = NULL;
  145.  
  146.     /* Open the output file */
  147.     if (fh = Open (filename, MODE_NEWFILE))
  148.     {
  149.         struct List *list = (struct List *) oi->oi_UserData;
  150.         STRPTR base = "obj";
  151.  
  152.         MakeHeader (fh, name, filename);
  153.  
  154.         /* Find the base name of the environment */
  155.         HandleList (&(oi->oi_ObjList), findbase, &base);
  156.  
  157.         if (list)
  158.         {
  159.         /* Do the list, calling dumpfcid for every node */
  160.         HandleList (list, dumpfcid, oi, fh, base);
  161.  
  162.         /* Get a blank line in there */
  163.         fprint (fh, "\n    LAST_ID\n};\n\n", NULL);
  164.  
  165.         /* Do the list, calling dumpfunc for every node */
  166.         HandleList (list, dumpproto, oi, fh, base);
  167.  
  168.         /* Blank line */
  169.         fprint (fh, "\n", NULL);
  170.  
  171.         /* Do the list, calling dumpfunc for every node */
  172.         HandleList (list, makeappdata, oi, fh, base);
  173.  
  174.         /* Blank line */
  175.         fprint (fh, "};\n\n", NULL);
  176.         }
  177.  
  178.         fprint (fh, FILL, NULL);
  179.         fprint (fh, "/* Window environment data */\n", NULL);
  180.         fprint (fh, FILL, NULL);
  181.         fprint (fh, "\n", NULL);
  182.  
  183.         if (list)
  184.         {
  185.         /* Do the list, calling dumpfunc for every node */
  186.         HandleList (list, dumpfunc, oi, fh, base);
  187.  
  188.         /* Get a blank line in there */
  189.         fprint (fh, "};\n\n", NULL);
  190.  
  191.         }
  192.  
  193.         /* Do the list, calling dumptext for every node */
  194.         HandleList (&(oi->oi_ObjList), dumptext, oi, fh, base);
  195.  
  196.         /* Do the list, calling dumptagdata for every node */
  197.         HandleList (&(oi->oi_ObjList), dumptagdata, oi, fh, base);
  198.  
  199.         /* Do the list, calling dumptags for every node */
  200.         HandleList (&(oi->oi_ObjList), dumptags, oi, fh, base);
  201.  
  202.         /* Do the list, calling dumpobject for every node */
  203.         HandleList (&(oi->oi_ObjList), dumpobject, oi, fh, base);
  204.  
  205.  
  206.         fprint (fh, "/* These tags describe the window environment */\n", NULL);
  207.         fprint (fh, "struct TagItem %s_env[] =\n", base);
  208.         fprint (fh, "{\n", NULL);
  209.         fprint (fh, "    {APSH_NameTag, (ULONG) \"%s\"},\n", base);
  210.         fprint (fh, "    {APSH_Objects, (ULONG) %s},\n", base);
  211.         fprint (fh, "    {APSH_WinText, (ULONG) %s_deftext},\n", (LONG) base);
  212.         fprint (fh, "    {APSH_WinAOpen, %sWinOpenID},\n", (LONG) base);
  213.         fprint (fh, "    {APSH_WinBClose, %sWinCloseID},\n", (LONG) base);
  214.         fprint (fh, "    {TAG_DONE,}\n", NULL);
  215.         fprint (fh, "};\n\n", NULL);
  216.         fprint (fh, "#define WINDOW_ENV %s_env\n\n", (LONG) base);
  217.  
  218.         if (list)
  219.         {
  220.         fprint (fh, FILL, NULL);
  221.         fprint (fh, "/* Function stubs */\n", NULL);
  222.         fprint (fh, FILL, NULL);
  223.         fprint (fh, "\n", NULL);
  224.  
  225.         /* Do the list, calling dumpfunc for every node */
  226.         HandleList (list, makefunc, oi, fh, base);
  227.         }
  228.  
  229.         /* Close the file */
  230.         Close (fh);
  231.     }
  232.     }
  233. }
  234.  
  235. static VOID MakeHeader (BPTR fh, STRPTR name, STRPTR filename)
  236. {
  237.  
  238.     fprint (fh, "/* %s --- data for %s\n", filename, name);
  239.     fprint (fh, " *\n */\n\n", NULL);
  240.  
  241.     fprint (fh, FILL, NULL);
  242.     fprint (fh, "/* Place this section in a global header file */\n", NULL);
  243.     fprint (fh, FILL, NULL);
  244.     fprint (fh, "\n", NULL);
  245.  
  246.     fprint (fh, "#include <exec/types.h>\n", NULL);
  247.     fprint (fh, "#include <libraries/appshell.h>\n", NULL);
  248.     fprint (fh, "#include <libraries/apshattrs.h>\n", NULL);
  249.     fprint (fh, "#include <libraries/appobjects.h>\n", NULL);
  250.     fprint (fh, "#include <libraries/gadtools.h>\n", NULL);
  251.     fprint (fh, "#include <clib/appshell_protos.h>\n", NULL);
  252.     fprint (fh, "#include <clib/appobjects_protos.h>\n", NULL);
  253.     fprint (fh, "#include <clib/gadtools_protos.h>\n", NULL);
  254.     fprint (fh, "#include <clib/utility_protos.h>\n", NULL);
  255.     fprint (fh, "#include \"ae:support/misc_protos.h\"\n", NULL);
  256.     fprint (fh, "#include <pragmas/appshell.h>\n", NULL);
  257.     fprint (fh, "#include <pragmas/appobjects.h>\n", NULL);
  258.     fprint (fh, "#include <pragmas/gadtools.h>\n", NULL);
  259.     fprint (fh, "#include <pragmas/utility.h>\n", NULL);
  260.     fprint (fh, "\n", NULL);
  261.     fprint (fh, "extern struct Library *SysBase, *DOSBase;\n", NULL);
  262.     fprint (fh, "extern struct Library *AppShellBase, *AppObjectsBase;\n", NULL);
  263.     fprint (fh, "extern struct Library *IntuitionBase, *GadToolsBase, *GfxBase, *UtilityBase;\n", NULL);
  264.     fprint (fh, "\n", NULL);
  265. }
  266.  
  267. static VOID findbase (struct ObjectNode * on, ULONG cnt, struct GetRec * gr)
  268. {
  269.  
  270.     if (on)
  271.     {
  272.     struct Object *o = &(on->on_Object);
  273.  
  274.     if (o->o_Type == OBJ_Window)
  275.     {
  276.         *gr->gr_BaseName = o->o_Name;
  277.     }
  278.     }
  279. }
  280.  
  281. static VOID dumpfcid (struct FuncsNode * fn, ULONG cnt, struct DumpRec * dr)
  282. {
  283.     struct ObjectInfo *oi = dr->dr_OI;
  284.  
  285.     if (fn && oi)
  286.     {
  287.     STRPTR name = fn->fn_Func.fe_Name;
  288.     BPTR fh = dr->dr_FH;
  289.  
  290.     /* First text item? */
  291.     if (cnt == 0)
  292.     {
  293.         fprint (fh, "/* Function ID's */\n", NULL);
  294.         fprint (fh, "enum\n{\n    Dummy = APSH_USER_ID,\n\n", NULL);
  295.         fprint (fh, "    Open%sID,\n", (LONG) dr->dr_BaseName);
  296.         fprint (fh, "    %sWinOpenID,\n", (LONG) dr->dr_BaseName);
  297.         fprint (fh, "    %sWinCloseID,\n", (LONG) dr->dr_BaseName);
  298.     }
  299.  
  300.     if (name && (strlen (name) > 0))
  301.     {
  302.         /* Print the enum name */
  303.         fprint (fh, "    %sID,\n", (LONG) name);
  304.     }
  305.     }
  306. }
  307.  
  308. static VOID dumpproto (struct FuncsNode * fn, ULONG cnt, struct DumpRec * dr)
  309. {
  310.     if (fn)
  311.     {
  312.     STRPTR name = fn->fn_Func.fe_Name;
  313.     BPTR fh = dr->dr_FH;
  314.  
  315.     /* First text item? */
  316.     if (cnt == 0)
  317.     {
  318.         fprint (fh, "/* Function prototypes */\n", NULL);
  319.         fprint (fh, "VOID Open%sFunc(struct AppInfo *, STRPTR, struct TagItem *);\n", (LONG) dr->dr_BaseName);
  320.         fprint (fh, "VOID %sWinOpenFunc(struct AppInfo *, STRPTR, struct TagItem *);\n", (LONG) dr->dr_BaseName);
  321.         fprint (fh, "VOID %sWinCloseFunc(struct AppInfo *, STRPTR, struct TagItem *);\n", (LONG) dr->dr_BaseName);
  322.     }
  323.  
  324.     if (name && (strlen (name) > 0))
  325.     {
  326.         fprint (fh, "VOID %sFunc(struct AppInfo *, STRPTR, struct TagItem *);\n", (LONG) name);
  327.     }
  328.     }
  329. }
  330.  
  331. static VOID dumpfunc (struct FuncsNode * fn, ULONG cnt, struct DumpRec * dr)
  332. {
  333.     if (fn)
  334.     {
  335.     STRPTR name = fn->fn_Func.fe_Name;
  336.     struct ObjectNode *on = fn->fn_Obj;
  337.     BPTR fh = dr->dr_FH;
  338.     ULONG type = 0;
  339.  
  340.     if (on)
  341.     {
  342.         type = on->on_Object.o_Type;
  343.     }
  344.     else
  345.     {
  346.         type = (ULONG) fn->fn_Func.fe_GroupID;
  347.     }
  348.  
  349.     /* First text item? */
  350.     if (cnt == 0)
  351.     {
  352.         fprint (fh, "/* Function table */\n", NULL);
  353.         fprint (fh, "struct Funcs app_funcs[] =\n{\n", NULL);
  354.         fprint (fh, "    {\"Open%s\", Open%sFunc, Open%sID, \",\", 0, },\n", dr->dr_BaseName, dr->dr_BaseName, dr->dr_BaseName);
  355.         fprint (fh, "    {\"%sWinOpen\", %sWinOpenFunc, %sWinOpenID, \",\", 0, APSHF_PRIVATE, },\n", dr->dr_BaseName, dr->dr_BaseName, dr->dr_BaseName);
  356.         fprint (fh, "    {\"%sWinClose\", %sWinCloseFunc, %sWinCloseID, \",\", 0, APSHF_PRIVATE, },\n", dr->dr_BaseName, dr->dr_BaseName, dr->dr_BaseName);
  357.     }
  358.  
  359.     if (name && (strlen (name) > 0))
  360.     {
  361.         fprint (fh, "    {\"%s\", %sFunc, %sID,", name, name, name);
  362.  
  363.         switch (type)
  364.         {
  365.         case OBJ_Checkbox:
  366.             fprint (fh, " \"OFF/S\", 1, },\n", NULL);
  367.             break;
  368.  
  369.         case OBJ_Integer:
  370.         case OBJ_Number:
  371.         case OBJ_DirNumeric:
  372.             fprint (fh, " \"NUM/N\", 1, },\n", NULL);
  373.             break;
  374.  
  375.         case OBJ_Listview:
  376.             fprint (fh, " \"ACTIVE/N,TOP/K/N\", 2, },\n", NULL);
  377.             break;
  378.  
  379.         case OBJ_MX:
  380.         case OBJ_Cycle:
  381.             fprint (fh, " \"ACTIVE/N\", 1, },\n", NULL);
  382.             break;
  383.  
  384.         case OBJ_Palette:
  385.             fprint (fh, " \"COLOR/N\", 1, },\n", NULL);
  386.             break;
  387.  
  388.         case OBJ_Scroller:
  389.             fprint (fh, " \"TOP/N,TOTAL/K/N,VISIBLE/K/N\", 3, },\n", NULL);
  390.             break;
  391.  
  392.         case OBJ_Slider:
  393.             fprint (fh, " \"LEVEL/N,MIN/K/N,MAX/K/N\", 3, },\n", NULL);
  394.             break;
  395.  
  396.         case OBJ_String:
  397.         case OBJ_Text:
  398.         case OBJ_DirString:
  399.         case OBJ_MultiText:
  400.             fprint (fh, " \"TEXT\", 1, },\n", NULL);
  401.             break;
  402.  
  403.         case OBJ_Button:
  404.         case OBJ_Display:
  405.         case OBJ_Select:
  406.         default:
  407.             fprint (fh, " \",\", 0, },\n", NULL);
  408.             break;
  409.         }
  410.     }
  411.     }
  412. }
  413.  
  414. static VOID makeappdata (struct FuncsNode * fn, ULONG cnt, struct DumpRec * dr)
  415. {
  416.     struct TagItem *attrs = NULL;
  417.     STRPTR name = NULL;
  418.     LONG num;
  419.  
  420.     if (fn)
  421.     {
  422.     struct ObjectNode *on = fn->fn_Obj;
  423.     BPTR fh = dr->dr_FH;
  424.     ULONG type = 0;
  425.  
  426.     /* First text item? */
  427.     if (cnt == 0)
  428.     {
  429.         fprint (fh, "/* Application Data */\n", NULL);
  430.         fprint (fh, "struct AppData\n{\n", NULL);
  431.     }
  432.  
  433.     if (on)
  434.     {
  435.         attrs = on->on_OTags;
  436.         type = on->on_Object.o_Type;
  437.         name = on->on_Object.o_Name;
  438.     }
  439.     else
  440.     {
  441.         type = (ULONG) fn->fn_Func.fe_GroupID;
  442.         name = fn->fn_Func.fe_Name;
  443.     }
  444.  
  445.     /* See if we're attached to a gadget */
  446.     if (name && (strlen (name) > 0))
  447.     {
  448.         switch (type)
  449.         {
  450.         case OBJ_Button:
  451.         case OBJ_Display:
  452.         case OBJ_Select:
  453.             break;
  454.  
  455.         case OBJ_Checkbox:
  456.             fprint (fh, "    BOOL ad_%s;\n", name);
  457.             break;
  458.  
  459.         case OBJ_Integer:
  460.         case OBJ_Number:
  461.         case OBJ_DirNumeric:
  462.             fprint (fh, "    LONG ad_%s;\n", name);
  463.             break;
  464.  
  465.         case OBJ_Listview:
  466.             fprint (fh, "    struct List ad_%sList;\n", name);
  467.             fprint (fh, "    ULONG ad_%s;\n", name);
  468.             break;
  469.  
  470.             break;
  471.  
  472.         case OBJ_MX:
  473.         case OBJ_Cycle:
  474.         case OBJ_Palette:
  475.         case OBJ_Scroller:
  476.         case OBJ_Slider:
  477.             fprint (fh, "    UWORD ad_%s;\n", name);
  478.             break;
  479.  
  480.         case OBJ_String:
  481.         case OBJ_Text:
  482.         case OBJ_DirString:
  483.             num = GetTagData (GTST_MaxChars, 10, attrs);
  484.             fprint (fh, "    UBYTE ad_%s[%ld];\n", name, num);
  485.             break;
  486.  
  487.         case OBJ_Dropbox:
  488.             break;
  489.  
  490.         case OBJ_GImage:
  491.             break;
  492.  
  493.         case OBJ_MultiText:
  494.             num = GetTagData (STRINGA_MaxChars, 10, attrs);
  495.             fprint (fh, "    UBYTE ad_%s[%ld];\n", name, num);
  496.             break;
  497.         }
  498.     }
  499.     }
  500. }
  501.  
  502. STRPTR openfunc_arg[] =
  503. {
  504.     "{\n",
  505.     "    struct AppData *ad = (struct AppData *) ai->ai_UserData;\n",
  506.     "\n",
  507.     "    /* Open the window */\n",
  508.     "    HandlerFunc (ai,\n",
  509.     "         APSH_Handler, \"IDCMP\",\n",
  510.     "         APSH_Command, APSH_MH_OPEN,\n",
  511.     "         APSH_WindowEnv, (ULONG) WINDOW_ENV,\n",
  512.     "         TAG_DONE);\n",
  513.     "}\n\n",
  514.     NULL
  515. };
  516.  
  517. STRPTR wopenfunc_arg[] =
  518. {
  519.     "{\n",
  520.     "    struct AppData *ad = (struct AppData *) ai->ai_UserData;\n",
  521.     "\n",
  522.     "    /* This gets called after the window is opened */\n",
  523.     "}\n\n",
  524.     NULL
  525. };
  526.  
  527. STRPTR wclosefunc_arg[] =
  528. {
  529.     "{\n",
  530.     "    struct AppData *ad = (struct AppData *) ai->ai_UserData;\n",
  531.     "\n",
  532.     "    /* This gets called before the window is closed */\n",
  533.     "}\n\n",
  534.     NULL
  535. };
  536.  
  537. VOID print_array (BPTR fh, STRPTR * array)
  538. {
  539.     WORD i = 0;
  540.  
  541.     while (array[i])
  542.     {
  543.     fprint (fh, array[i++], NULL);
  544.     }
  545. }
  546.  
  547. static VOID makefunc (struct FuncsNode * fn, ULONG cnt, struct DumpRec * dr)
  548. {
  549.     STRPTR name = NULL;
  550.  
  551.     if (fn)
  552.     {
  553.     BPTR fh = dr->dr_FH;
  554.     struct ObjectNode *on = fn->fn_Obj;
  555.     struct TagItem *attrs = NULL;
  556.     STRPTR dname = NULL;
  557.     ULONG type = 0;
  558.  
  559.     if (on)
  560.     {
  561.         attrs = on->on_OTags;
  562.         type = on->on_Object.o_Type;
  563.         dname = on->on_Object.o_Name;
  564.     }
  565.     else
  566.     {
  567.         type = (ULONG) fn->fn_Func.fe_GroupID;
  568.         dname = fn->fn_Func.fe_Name;
  569.     }
  570.  
  571.     /* First text item? */
  572.     if (cnt == 0)
  573.     {
  574.         fprint (fh, "VOID Open%sFunc(struct AppInfo *ai, STRPTR cmd, struct TagItem *attrs)\n", dr->dr_BaseName);
  575.         print_array (fh, openfunc_arg);
  576.  
  577.         fprint (fh, "VOID %sWinOpenFunc(struct AppInfo *ai, STRPTR cmd, struct TagItem *attrs)\n", dr->dr_BaseName);
  578.         print_array (fh, wopenfunc_arg);
  579.  
  580.         fprint (fh, "VOID %sWinCloseFunc(struct AppInfo *ai, STRPTR cmd, struct TagItem *attrs)\n", dr->dr_BaseName);
  581.         print_array (fh, wclosefunc_arg);
  582.     }
  583.  
  584. /* Decode argument types */
  585.  
  586.     /* See if we're attached to a gadget */
  587.     if ((name = fn->fn_Func.fe_Name) && (strlen (name) > 0) && (type > 0))
  588.     {
  589.         WORD ngad = 0;
  590.  
  591.         /* See if we need gadget refresh... */
  592.         switch (type)
  593.         {
  594.         case OBJ_Integer:
  595.         case OBJ_Number:
  596.         case OBJ_DirNumeric:
  597.         case OBJ_String:
  598.         case OBJ_DirString:
  599.         case OBJ_MultiText:
  600.             ngad = 1;
  601.             break;
  602.  
  603.         case OBJ_Checkbox:
  604.         case OBJ_MX:
  605.         case OBJ_Cycle:
  606.         case OBJ_Palette:
  607.         case OBJ_Scroller:
  608.         case OBJ_Slider:
  609.             ngad = 2;
  610.             break;
  611.         }
  612.  
  613.         fprint (fh, "VOID %sFunc(struct AppInfo *ai, STRPTR cmd, struct TagItem *attrs)\n", name);
  614.         fprint (fh, "{\n", NULL);
  615.         fprint (fh, "    struct AppData *ad = (struct AppData *) ai->ai_UserData;\n", NULL);
  616.  
  617.         /* Declare the variables needed for gadget refresh */
  618.         if (ngad)
  619.         {
  620.         /* Got to pull something from the msg->Code field */
  621.         if (ngad == 2)
  622.         {
  623.             fprint (fh, "    struct TagItem *tag;\n", NULL);
  624.         }
  625.         else
  626.         {
  627.             fprint (fh, "    BOOL update = FALSE;\n", NULL);
  628.         }
  629.  
  630.         fprint (fh, "    struct Window *win;\n", NULL);
  631.         fprint (fh, "    struct Gadget *gad;\n", NULL);
  632.         }
  633.  
  634.         fprint (fh, "    struct Funcs *f;\n", NULL);
  635.         fprint (fh, "\n", NULL);
  636.         fprint (fh, "    /* See if we have preparsed command line. */\n", NULL);
  637.         fprint (fh, "    if (f = (struct Funcs *) GetTagData (APSH_FuncEntry, NULL, attrs))\n", NULL);
  638.         fprint (fh, "    {\n", NULL);
  639.  
  640.         /* Get the parsed variable */
  641.         switch (type)
  642.         {
  643.         case OBJ_Checkbox:
  644.             fprint (fh, "    /* Get a boolean option */\n", NULL);
  645.             fprint (fh, "    ad->ad_%s = (BOOL) (f->fe_Options[0]) ? FALSE : TRUE;\n", dname);
  646.             break;
  647.  
  648.         case OBJ_Integer:
  649.         case OBJ_Number:
  650.         case OBJ_DirNumeric:
  651.  
  652.         case OBJ_MX:
  653.         case OBJ_Cycle:
  654.         case OBJ_Palette:
  655.         case OBJ_Scroller:
  656.         case OBJ_Slider:
  657.             fprint (fh, "    /* Get a numeric option */\n", NULL);
  658.             fprint (fh, "    ad->ad_%s = *((LONG *) f->fe_Options[0]);\n", dname);
  659.             break;
  660.  
  661.         case OBJ_String:
  662.         case OBJ_DirString:
  663.         case OBJ_MultiText:
  664.             fprint (fh, "    /* Get a text option */\n", NULL);
  665.             fprint (fh, "    strcpy (ad->ad_%s, (STRPTR) f->fe_Options[0]);\n", dname);
  666.             break;
  667.         }
  668.  
  669.         /* Show that an update is needed */
  670.         if (ngad)
  671.         {
  672.         STRPTR tv = "TAG_IGNORE";
  673.  
  674.         if (ngad == 2)
  675.         {
  676.             fprint (fh, "\n    /* Get the gadget information */\n", NULL);
  677.             fprint (fh, "    if (APSHGetGadgetInfo (ai, \"%s\", \"%s\",\n", dr->dr_BaseName, dname);
  678.             fprint (fh, "                   (ULONG *)&win, (ULONG *)&gad))\n", NULL);
  679.             fprint (fh, "    {\n", NULL);
  680.             if (type == OBJ_Scroller)
  681.             {
  682.             fprint (fh, "        SetGadgetAttrs (gad, win, NULL,\n", NULL);
  683.             }
  684.             else
  685.             {
  686.             fprint (fh, "        GT_SetGadgetAttrs (gad, win, NULL,\n", NULL);
  687.             }
  688.  
  689.             switch (type)
  690.             {
  691.             case OBJ_Checkbox:
  692.                  tv = "GTCB_Checked";
  693.                  break;
  694.  
  695.             case OBJ_MX:
  696.                  tv = "GTMX_Active";
  697.                  break;
  698.  
  699.             case OBJ_Cycle:
  700.                  tv = "GTCY_Active";
  701.                  break;
  702.  
  703.             case OBJ_Palette:
  704.                  tv = "GTPA_Color";
  705.                  break;
  706.  
  707.             case OBJ_Scroller:
  708.                  tv = "GTSC_Top";
  709.                  break;
  710.  
  711.             case OBJ_Slider:
  712.                  tv = "GTSL_Level";
  713.                  break;
  714.             }
  715.  
  716.             fprint (fh, "                %s, ad->ad_%s,\n", tv, dname);
  717.             fprint (fh, "                TAG_DONE);\n", NULL);
  718.             fprint (fh, "    }\n", NULL);
  719.         }
  720.         else
  721.         {
  722.             fprint (fh, "\n    /* Indicate that gadget needs to be refreshed */\n", NULL);
  723.             fprint (fh, "    update = TRUE;\n", NULL);
  724.         }
  725.         }
  726.  
  727.         fprint (fh, "    }\n", NULL);
  728.  
  729. /* Where do we get the parameters */
  730.  
  731.         /* Do we need to get a gadget... */
  732.         if (ngad == 1)
  733.         {
  734.         fprint (fh, "\n", NULL);
  735.         fprint (fh, "    /* Get the gadget information */\n", NULL);
  736.         fprint (fh, "    if (APSHGetGadgetInfo (ai, \"%s\", \"%s\",\n", dr->dr_BaseName, dname);
  737.         fprint (fh, "                   (ULONG *) & win, (ULONG *) & gad))\n", NULL);
  738.         fprint (fh, "    {\n", NULL);
  739.         }
  740.  
  741.         switch (type)
  742.         {
  743.         case OBJ_Integer:
  744.         case OBJ_DirNumeric:
  745.             fprint (fh, "    if (update)\n", NULL);
  746.             fprint (fh, "    {\n", NULL);
  747.             fprint (fh, "        /* Update the numeric gadget if there is one */\n", NULL);
  748.             fprint (fh, "        GT_SetGadgetAttrs (gad, win, NULL,\n", NULL);
  749.             fprint (fh, "                   GTIN_Number, (ULONG) ad->ad_%s,\n", dname);
  750.             fprint (fh, "                   TAG_DONE);\n", NULL);
  751.             fprint (fh, "    }\n", NULL);
  752.             fprint (fh, "    else\n", NULL);
  753.             fprint (fh, "    {\n", NULL);
  754.             fprint (fh, "        ad->ad_%s = ((struct StringInfo *) gad->SpecialInfo)->LongInt;\n", dname);
  755.             fprint (fh, "    }\n", NULL);
  756.             break;
  757.  
  758.         case OBJ_String:
  759.         case OBJ_DirString:
  760.             fprint (fh, "    if (update)\n", NULL);
  761.             fprint (fh, "    {\n", NULL);
  762.             fprint (fh, "        /* Update the string gadget if there is one */\n", NULL);
  763.             fprint (fh, "        GT_SetGadgetAttrs (gad, win, NULL,\n", NULL);
  764.             fprint (fh, "                   GTST_String, (ULONG) ad->ad_%s,\n", dname);
  765.             fprint (fh, "                   TAG_DONE);\n", NULL);
  766.             fprint (fh, "    }\n", NULL);
  767.             fprint (fh, "    else\n", NULL);
  768.             fprint (fh, "    {\n", NULL);
  769.             fprint (fh, "        strcpy (ad->ad_%s, (STRPTR) ((struct StringInfo *) gad->SpecialInfo)->Buffer);\n", dname);
  770.             fprint (fh, "    }\n", NULL);
  771.             break;
  772.  
  773.         case OBJ_MultiText:
  774.             fprint (fh, "    if (update)\n", NULL);
  775.             fprint (fh, "    {\n", NULL);
  776.             fprint (fh, "        /* Update the multiline text gadget if there is one */\n", NULL);
  777.             fprint (fh, "        SetGadgetAttrs (gad, win, NULL,\n", NULL);
  778.             fprint (fh, "                STRINGA_TextVal, ad->ad_%s,\n", dname);
  779.             fprint (fh, "                TAG_DONE);\n", NULL);
  780.             fprint (fh, "    }\n", NULL);
  781.             fprint (fh, "    else\n", NULL);
  782.             fprint (fh, "    {\n", NULL);
  783.             fprint (fh, "        strcpy (ad->ad_%s, (STRPTR) ((struct StringInfo *) gad->SpecialInfo)->Buffer);\n", dname);
  784.             fprint (fh, "    }\n", NULL);
  785.             break;
  786.  
  787. /* NOT DONE YET */
  788.  
  789.         case OBJ_Listview:
  790.             fprint (fh, "    else\n", NULL);
  791.             fprint (fh, "    {\n", NULL);
  792.             fprint (fh, "    struct List *list = &(ad->ad_%sList);\n", dname);
  793.             fprint (fh, "    struct TagItem *tag;\n", NULL);
  794.             fprint (fh, "    struct Node *node;\n", NULL);
  795.             fprint (fh, "\n", NULL);
  796.             fprint (fh, "    /* Find the selected item in a list */\n", NULL);
  797.             fprint (fh, "    if (tag = FindTagItem (APSH_MsgCode, attrs))\n", NULL);
  798.             fprint (fh, "    {\n", NULL);
  799.             fprint (fh, "        /* Which line was selected */\n", NULL);
  800.             fprint (fh, "        ad->ad_%s = (WORD) tag->ti_Data;\n", dname);
  801.             fprint (fh, "\n", NULL);
  802.             fprint (fh, "        /* Locate the corresponding node in the list */\n", NULL);
  803.             fprint (fh, "        if (node = FindSelected (list, ad->ad_%s))\n", dname);
  804.             fprint (fh, "        {\n", NULL);
  805.             fprint (fh, "        /* Use the node... */\n", NULL);
  806.             fprint (fh, "        }\n", NULL);
  807.             fprint (fh, "    }\n", NULL);
  808.             fprint (fh, "    }\n", NULL);
  809.             break;
  810.  
  811.         case OBJ_Checkbox:
  812.         case OBJ_MX:
  813.         case OBJ_Cycle:
  814.         case OBJ_Palette:
  815.         case OBJ_Scroller:
  816.         case OBJ_Slider:
  817.             fprint (fh, "    else if (tag = FindTagItem (APSH_MsgCode, attrs))\n", NULL);
  818.             fprint (fh, "    {\n", NULL);
  819.             fprint (fh, "    ad->ad_%s = (UWORD) tag->ti_Data;\n", dname);
  820.             fprint (fh, "    }\n", NULL);
  821.             break;
  822.         }
  823.  
  824.         /* Do we need to end the get gadget... */
  825.         if (ngad == 1)
  826.         {
  827.         fprint (fh, "    }\n", NULL);
  828.         }
  829.  
  830.         fprint (fh, "}\n\n", NULL);
  831.     }
  832.     }
  833. }
  834.  
  835. static VOID dumptext (struct ObjectNode * on, ULONG cnt, struct DumpRec * dr)
  836. {
  837.     if (on)
  838.     {
  839.     struct ObjectInfo *oi = dr->dr_OI;
  840.     struct Object *o = &(on->on_Object);
  841.     STRPTR *text = oi->oi_TextTable;
  842.     BPTR fh = dr->dr_FH;
  843.  
  844.     /* First text item? */
  845.     if (cnt == 0)
  846.     {
  847.         fprint (fh, "STRPTR %s_deftext[] =\n{\n    \"\",\n", dr->dr_BaseName);
  848.     }
  849.  
  850.     /* Do we have tags? */
  851.     if (o->o_LabelID)
  852.     {
  853.         fprint (fh, "    \"%s\",\n", text[o->o_LabelID]);
  854.     }
  855.  
  856.     /* Is there an object after this one? */
  857.     if (o->o_NextObject == NULL)
  858.     {
  859.         fprint (fh, "    NULL\n};\n\n", NULL);
  860.     }
  861.     }
  862. }
  863.  
  864. static VOID ImageToC (BPTR fh, STRPTR name, struct Image * i)
  865. {
  866.     int w, h, d, c, t, cp;
  867.     register int j, k;
  868.     USHORT *data;
  869.  
  870.     /* Image data portion */
  871.     fprint (fh, "UWORD chip %s_idata[] =\n{\n", name);
  872.     w = i->Width;
  873.     h = i->Height;
  874.     d = i->Depth;
  875.     c = ((w + 15) / 16) * h;
  876.     cp = 0;
  877.     data = i->ImageData;
  878.     for (k = 0; k < d; k++)
  879.     {
  880.     if (k > 0)
  881.         fprint (fh, "\n", NULL);
  882.     fprint (fh, "/* Plane %ld */\n    ", (LONG) k);
  883.     t = 0;
  884.     for (j = 0; j < c; j++)
  885.     {
  886.         if (t > 7)
  887.         {
  888.         fprint (fh, "\n    ", NULL);
  889.         t = 0;
  890.         }
  891.         t++;
  892.         fprint (fh, "0x%04lx,", (LONG) data[cp++]);
  893.     }
  894.     }
  895.     fprint (fh, "\n};\n\n", NULL);
  896.  
  897.     /* Image structure portion */
  898.     fprint (fh, "static struct Image %s_data =\n{\n", name);
  899.     fprint (fh, "    %ld, %ld,            /* Upper left corner */\n",
  900.         (LONG) i->LeftEdge, (LONG) i->TopEdge);
  901.     fprint (fh, "    %ld, %ld, %ld,            /* Width, Height, Depth */\n",
  902.         (LONG) w, (LONG) h, (LONG) d);
  903.     fprint (fh, "    %s_idata,        /* Image data */\n", name);
  904.     fprint (fh, "    0x%04lx, 0x%04lx,        /* PlanePick, PlaneOnOff */\n",
  905.         (LONG) i->PlanePick, (LONG) i->PlaneOnOff);
  906.     fprint (fh, "    NULL            /* Next image */\n", NULL);
  907.     fprint (fh, "};\n\n", NULL);
  908. }
  909.  
  910. static VOID dumplist (struct Node * n, ULONG cnt, struct PrintRec * pr)
  911. {
  912.     BPTR fh = pr->pr_FH;
  913.  
  914.     fprint (fh, "    \"%s\",\n", n->ln_Name);
  915. }
  916.  
  917. static VOID printtagdata (BPTR fh, STRPTR name, ULONG t, struct TagItem * tl)
  918. {
  919.     struct TagItem *tags = tl;
  920.     struct TagItem *tag;
  921.     ULONG td, tv;
  922.  
  923.     while (tag = NextTagItem (&tags))
  924.     {
  925.     tv = tag->ti_Tag;
  926.     td = tag->ti_Data;
  927.  
  928.     if (tv == GTLV_Labels)
  929.     {
  930.         fprint (fh, "static STRPTR %s_data[] =\n{\n", name);
  931.  
  932.         /* Find the base name of the environment */
  933.         HandleList ((struct List *) td, dumplist, fh);
  934.  
  935.         fprint (fh, "    NULL\n};\n\n", NULL);
  936.     }
  937.     else if ((tv == GTCY_Labels) || (tv == GTMX_Labels))
  938.     {
  939.         STRPTR *text = (STRPTR *) td;
  940.         WORD i = 0;
  941.  
  942.         fprint (fh, "static STRPTR %s_data[] =\n{\n", name);
  943.  
  944.         while (text[i])
  945.         {
  946.         fprint (fh, "    \"%s\",\n", text[i]);
  947.         i++;
  948.         }
  949.  
  950.         fprint (fh, "    NULL\n};\n\n", NULL);
  951.     }
  952.     else if (tv == APSH_ObjData)
  953.     {
  954.         ImageToC (fh, name, (struct Image *) td);
  955.     }
  956.     }
  957. }
  958.  
  959. STRPTR wintags[] =
  960. {
  961.     "APSH_WindowEnv",
  962.     "APSH_TextAttr",
  963.     "APSH_NewScreen",
  964.     "APSH_NewScreenTags",
  965.     "APSH_Palette",
  966.     "APSH_NewWindow",
  967.     "APSH_NewWindowTags",
  968.     "APSH_HotKeys",
  969.     "APSH_Menu",
  970.     "APSH_Gadgets",
  971.     "APSH_GTMenu",
  972.     "APSH_GTGadgets",
  973.     "APSH_GTFlags",
  974.     "APSH_Objects",
  975.     "APSH_ObjDown",
  976.     "APSH_ObjHold",
  977.     "APSH_ObjRelease",
  978.     "APSH_ObjDblClick",
  979.     "APSH_ObjAbort",
  980.     "APSH_ObjAltHit",
  981.     "APSH_ObjShiftHit",
  982.     "APSH_ObjData",
  983.     "APSH_ObjInner",
  984.     "APSH_ObjPointer",
  985.     "APSH_DefWinFlags",
  986.     "APSH_ObjName",
  987.     "APSH_WinName",
  988.     NULL,
  989.     "APSH_WinPointer",
  990.     "APSH_ShowSelected",
  991.     "APSH_Screen",
  992.     "APSH_ObjExtraRelease",
  993.     "APSH_ObjAltData",
  994.     "APSH_ParentWindow",
  995.     "APSH_TTMenu",
  996.     NULL
  997. };
  998.  
  999. STRPTR gadtool1[] =
  1000. {
  1001.     "GTVI_NewWindow",
  1002.     "GTVI_NWTags",
  1003.     "GT_Private0",
  1004.     "GTCB_Checked",
  1005.     "GTLV_Top",
  1006.     "GTLV_Labels",
  1007.     "GTLV_ReadOnly",
  1008.     "GTLV_ScrollWidth",
  1009.     "GTMX_Labels",
  1010.     "GTMX_Active",
  1011.     "GTTX_Text",
  1012.     "GTTX_CopyText",
  1013.     "GTNM_Number",
  1014.     "GTCY_Labels",
  1015.     "GTCY_Active",
  1016.     "GTPA_Depth",
  1017.     "GTPA_Color",
  1018.     "GTPA_ColorOffset   ",
  1019.     "GTPA_IndicatorWidth",
  1020.     "GTPA_IndicatorHeigh",
  1021.     "GTSC_Top",
  1022.     "GTSC_Total",
  1023.     "GTSC_Visible",
  1024.     "GTSC_Overlap",
  1025.     NULL
  1026. };
  1027.  
  1028. STRPTR gadtool2[] =
  1029. {
  1030.     "GTSL_Min",
  1031.     "GTSL_Max",
  1032.     "GTSL_Level",
  1033.     "GTSL_MaxLevelLen",
  1034.     "GTSL_LevelFormat",
  1035.     "GTSL_LevelPlace",
  1036.     "GTSL_DispFunc",
  1037.     "GTST_String",
  1038.     "GTST_MaxChars",
  1039.     "GTIN_Number",
  1040.     "GTIN_MaxChars",
  1041.     "GTMN_TextAttr",
  1042.     "GTMN_FrontPen",
  1043.     "GTBB_Recessed",
  1044.     "GT_VisualInfo",
  1045.     "GTLV_ShowSelected",
  1046.     "GTLV_Selected",
  1047.     "GT_Reserved0",
  1048.     "GT_Reserved1",
  1049.     "GTTX_Border",
  1050.     "GTNM_Border",
  1051.     "GTSC_Arrows",
  1052.     "GTMN_Menu",
  1053.     "GTMX_Spacing",
  1054.     NULL
  1055. };
  1056.  
  1057. STRPTR appobject1[] =
  1058. {
  1059.     "CGTA_reserved1",
  1060.     "CGTA_reserved2",
  1061.     "CGTA_HighPens",
  1062.     "CGTA_NextField",
  1063.     "CGTA_PrevField",
  1064.     "CGTA_Total",
  1065.     "CGTA_Visible",
  1066.     "CGTA_Top",
  1067.     "CGTA_List",
  1068.     NULL
  1069. };
  1070.  
  1071. STRPTR appobject2[] =
  1072. {
  1073.     "CGTA_Increment",
  1074.     "CGTA_Decrement",
  1075.     NULL
  1076. };
  1077.  
  1078. STRPTR appobject3[] =
  1079. {
  1080.     "CGTA_LabelInfo",
  1081.     "CGTA_Keystroke",
  1082.     "CGTA_Borderless",
  1083.     "CGTA_DisplayOnly",
  1084.     "CGTA_MinWidth",
  1085.     "CGTA_MinHeight",
  1086.     "CGTA_MaxWidth",
  1087.     "CGTA_MaxHeight",
  1088.     "CGTA_FrameInfo",
  1089.     "CGTA_Constraint",
  1090.     "CGTA_Nominal",
  1091.     "CGTA_TextAttr",
  1092.     "CGTA_Master",
  1093.     "CGTA_Transparent",
  1094.     "CGTA_InBorder",
  1095.     NULL
  1096. };
  1097.  
  1098. STRPTR intui1[] =
  1099. {
  1100.     "GA_LEFT",
  1101.     "GA_RELRIGHT",
  1102.     "GA_TOP",
  1103.     "GA_RELBOTTOM",
  1104.     "GA_WIDTH",
  1105.     "GA_RELWIDTH",
  1106.     "GA_HEIGHT",
  1107.     "GA_RELHEIGHT",
  1108.     "GA_TEXT",
  1109.     "GA_IMAGE",
  1110.     "GA_BORDER",
  1111.     "GA_SELECTRENDE",
  1112.     "GA_HIGHLIGHT",
  1113.     "GA_DISABLED",
  1114.     "GA_GZZGADGET",
  1115.     "GA_ID",
  1116.     "GA_USERDATA",
  1117.     "GA_SPECIALINFO",
  1118.     "GA_SELECTED",
  1119.     "GA_ENDGADGET",
  1120.     "GA_IMMEDIATE",
  1121.     "GA_RELVERIFY",
  1122.     "GA_FOLLOWMOUSE",
  1123.     "GA_RIGHTBORDER",
  1124.     "GA_LEFTBORDER",
  1125.     "GA_TOPBORDER",
  1126.     "GA_BOTTOMBORDER",
  1127.     "GA_TOGGLESELECT",
  1128.     "GA_SYSGADGET",
  1129.     "GA_SYSGTYPE",
  1130.     "GA_PREVIOUS",
  1131.     "GA_NEXT",
  1132.     "GA_DRAWINFO",
  1133.     "GA_INTUITEXT",
  1134.     "GA_LABELIMAGE",
  1135.     NULL
  1136. };
  1137.  
  1138. STRPTR intui2[] =
  1139. {
  1140.     "PGA_FREEDOM",
  1141.     "PGA_BORDERLESS",
  1142.     "PGA_HORIZPOT",
  1143.     "PGA_HORIZBODY",
  1144.     "PGA_VERTPOT",
  1145.     "PGA_VERTBODY",
  1146.     "PGA_TOTAL",
  1147.     "PGA_VISIBLE",
  1148.     "PGA_TOP",
  1149.     NULL
  1150. };
  1151.  
  1152. STRPTR intui3[] =
  1153. {
  1154.     "STRINGA_MaxChars",
  1155.     "STRINGA_Buffer",
  1156.     "STRINGA_UndoBuffer",
  1157.     "STRINGA_WorkBuffer",
  1158.     "STRINGA_BufferPos",
  1159.     "STRINGA_DispPos",
  1160.     "STRINGA_AltKeyMap",
  1161.     "STRINGA_Font",
  1162.     "STRINGA_Pens",
  1163.     "STRINGA_ActivePens",
  1164.     "STRINGA_EditHook",
  1165.     "STRINGA_EditModes",
  1166.     "STRINGA_ReplaceMode",
  1167.     "STRINGA_FixedFieldMode",
  1168.     "STRINGA_NoFilterMode",
  1169.     "STRINGA_Justification",
  1170.     "STRINGA_LongVal",
  1171.     "STRINGA_TextVal",
  1172.     NULL
  1173. };
  1174.  
  1175. STRPTR intui4[] =
  1176. {
  1177.     "WA_Left",
  1178.     "WA_Top",
  1179.     "WA_Width",
  1180.     "WA_Height",
  1181.     "WA_DetailPen",
  1182.     "WA_BlockPen",
  1183.     "WA_IDCMP",
  1184.     "WA_Flags",
  1185.     "WA_Gadgets",
  1186.     "WA_Checkmark",
  1187.     "WA_Title",
  1188.     "WA_ScreenTitle",
  1189.     "WA_CustomScreen",
  1190.     "WA_SuperBitMap",
  1191.     "WA_MinWidth",
  1192.     "WA_MinHeight",
  1193.     "WA_MaxWidth",
  1194.     "WA_MaxHeight",
  1195.     "WA_InnerWidth",
  1196.     "WA_InnerHeight",
  1197.     "WA_PubScreenName",
  1198.     "WA_PubScreen",
  1199.     "WA_PubScreenFallBack",
  1200.     "WA_WindowName",
  1201.     "WA_Colors",
  1202.     "WA_Zoom",
  1203.     "WA_MouseQueue",
  1204.     "WA_BackFill",
  1205.     "WA_RptQueue",
  1206.     "WA_SizeGadget",
  1207.     "WA_DragBar",
  1208.     "WA_DepthGadget",
  1209.     "WA_CloseGadget",
  1210.     "WA_Backdrop",
  1211.     "WA_ReportMouse",
  1212.     "WA_NoCareRefresh",
  1213.     "WA_Borderless",
  1214.     "WA_Activate",
  1215.     "WA_RMBTrap",
  1216.     "WA_WBenchWindow",
  1217.     "WA_SimpleRefresh",
  1218.     "WA_SmartRefresh",
  1219.     "WA_SizeBRight",
  1220.     "WA_SizeBBottom",
  1221.     "WA_AutoAdjust",
  1222.     "WA_GimmeZeroZero",
  1223.     NULL
  1224. };
  1225.  
  1226.  
  1227. STRPTR objname1[] =        /* 1 - 14 */
  1228. {
  1229.  /* GadTools gadgets */
  1230.     "OBJ_Generic",
  1231.     "OBJ_Button",
  1232.     "OBJ_Checkbox",
  1233.     "OBJ_Integer",
  1234.     "OBJ_Listview",
  1235.     "OBJ_MX",
  1236.     "OBJ_Number",
  1237.     "OBJ_Cycle",
  1238.     "OBJ_Palette",
  1239.     "OBJ_Scroller",
  1240.     "OBJ_reserved1",
  1241.     "OBJ_Slider",
  1242.     "OBJ_String",
  1243.     "OBJ_Text",
  1244.     NULL
  1245. };
  1246.  
  1247. STRPTR objname2[] =        /* 30 - 38 */
  1248. {
  1249.  /* other gadgets */
  1250.     "OBJ_Display",
  1251.     "OBJ_Select",
  1252.     "OBJ_Dropbox",
  1253.     "OBJ_GImage",
  1254.     "OBJ_MultiText",
  1255.     "OBJ_reserved2",
  1256.     "OBJ_DirString",
  1257.     "OBJ_DirNumeric",
  1258.     "OBJ_boopsi",
  1259.     NULL
  1260. };
  1261.  
  1262. STRPTR objname3[] =        /* 50 */
  1263. {
  1264.  /* images */
  1265.     "OBJ_Image",
  1266.     NULL
  1267. };
  1268.  
  1269. STRPTR objname4[] =        /* 60 - 64 */
  1270. {
  1271.  /* borders */
  1272.     "OBJ_reserved3",
  1273.     "OBJ_BevelIn",
  1274.     "OBJ_BevelOut",
  1275.     "OBJ_DblBevelIn",
  1276.     "OBJ_DblBevelOut",
  1277. };
  1278.  
  1279. STRPTR objname5[] =        /* 70 - 77 */
  1280. {
  1281.  /* other object types */
  1282.     "OBJ_Screen",
  1283.     "OBJ_Window",
  1284.     "OBJ_Group",
  1285.     "OBJ_VFill",
  1286.     "OBJ_HFill",
  1287.     "OBJ_VGroup",
  1288.     "OBJ_HGroup",
  1289.     "OBJ_MGroup",
  1290. };
  1291.  
  1292. /* a flag parsing method... convert Flag to Text */
  1293. struct ulongFlags
  1294. {
  1295.     ULONG uf_Flag;
  1296.     UBYTE *uf_Text;
  1297. };
  1298.  
  1299. struct ulongFlags GadToolsFlags[] =
  1300. {
  1301.     {0x0001, "PLACETEXT_LEFT"},
  1302.     {0x0002, "PLACETEXT_RIGHT"},
  1303.     {0x0004, "PLACETEXT_ABOVE"},
  1304.     {0x0008, "PLACETEXT_BELOW"},
  1305.     {0x0010, "PLACETEXT_IN"},
  1306.     {0x0020, "NG_HIGHLABEL"},
  1307.     {0x0040, "PLACETEXT_ABOVEC"},
  1308.     {0x0080, "PLACETEXT_ABOVEI"},
  1309.     {0x0100, "PLACETEXT_BELOWI"},
  1310.     {0x0200, "PLACETEXT_BELOWC"},
  1311.     {0, NULL}
  1312. };
  1313.  
  1314. struct ulongFlags ObjectFlags[] =
  1315. {
  1316.     {(1L << 0), "APSH_OBJF_ACTIVATE"},
  1317.     {(1L << 1), "APSH_OBJF_CLOSEWINDOW"},
  1318.     {(1L << 2), "APSH_OBJF_NOADJUST"},
  1319.     {0, NULL}
  1320. };
  1321.  
  1322. static VOID printFlags (BPTR fh, UBYTE * name, SHORT lvl, UBYTE * pref)
  1323. {
  1324.     static SHORT tlen = 0;
  1325.  
  1326.     if (lvl > 0)
  1327.     {
  1328.     if (tlen > 40)
  1329.     {
  1330.         fprint (fh, "\n%s", pref);
  1331.         tlen = 0;
  1332.     }
  1333.     fprint (fh, " | %s", name);
  1334.     }
  1335.     else
  1336.     {
  1337.     tlen = 0;
  1338.     fprint (fh, "%s", name);
  1339.     }
  1340.     tlen += strlen (name);
  1341. }
  1342.  
  1343. static VOID parseFlags (BPTR fh, ULONG flags, struct ulongFlags * uf,
  1344.              UBYTE * pref, UBYTE * sufx)
  1345. {
  1346.     USHORT j = 0;
  1347.  
  1348.     fprint (fh, "%s", pref);
  1349.     do
  1350.     {
  1351.     if (flags & uf->uf_Flag)
  1352.     {
  1353.         printFlags (fh, uf->uf_Text, j++, pref);
  1354.         flags &= ~uf->uf_Flag;    /* strip out used flags */
  1355.     }
  1356.     *uf++;
  1357.     } while (uf->uf_Text);
  1358.  
  1359.     if (j == 0)
  1360.     {
  1361.     if (flags == 0L)
  1362.         fprint (fh, "NULL", NULL);
  1363.     else
  1364.         fprint (fh, "0x0%lx", (LONG) flags);
  1365.     }
  1366.     else if (flags > 0L)
  1367.     {
  1368.     /* print out leftover flags */
  1369.     fprint (fh, " | 0x0%lx", (LONG) flags);
  1370.     }
  1371.     fprint (fh, "%s", sufx);
  1372. }
  1373.  
  1374. static VOID printtags (BPTR fh, STRPTR name, ULONG t, struct TagItem * tl)
  1375. {
  1376.     struct TagItem *tags = tl;
  1377.     struct TagItem *tag;
  1378.     ULONG td, tv;
  1379.  
  1380.     while (tag = NextTagItem (&tags))
  1381.     {
  1382.     td = tag->ti_Data;
  1383.     tv = tag->ti_Tag;
  1384.  
  1385.     if (tv == APSH_ObjName)
  1386.     {
  1387.         fprint (fh, "    {APSH_ObjName, (ULONG) \"%s\"},\n", td);
  1388.     }
  1389.     else if (tv == APSH_WinName)
  1390.     {
  1391.         fprint (fh, "    {APSH_WinName, (ULONG) \"%s\"},\n", td);
  1392.     }
  1393.     else if (tv == APSH_ShowSelected)
  1394.     {
  1395.         fprint (fh, "    {APSH_ShowSelected, (ULONG) \"%s\"},\n", td);
  1396.     }
  1397.     else if (tv == GTLV_Labels)
  1398.     {
  1399.         fprint (fh, "    {GTLV_Labels, (ULONG) %s_data},\n", name);
  1400.     }
  1401.     else if (tv == GTCY_Labels)
  1402.     {
  1403.         fprint (fh, "    {GTCY_Labels, (ULONG) %s_data},\n", name);
  1404.     }
  1405.     else if (tv == GTMX_Labels)
  1406.     {
  1407.         fprint (fh, "    {GTMX_Labels, (ULONG) %s_data},\n", name);
  1408.     }
  1409.     else if (tv == APSH_ObjData)
  1410.     {
  1411.         fprint (fh, "    {APSH_ObjData, (ULONG) &%s_data},\n", name);
  1412.     }
  1413.     else if (tv == APSH_GTFlags)
  1414.     {
  1415.         parseFlags (fh, (ULONG) td, &GadToolsFlags[0],
  1416.             "    {APSH_GTFlags, ", "},\n");
  1417.  
  1418.     }
  1419.     else if ((tv >= APSH_WindowEnv) && (tv <= APSH_TTMenu))
  1420.     {
  1421.         tv -= APSH_WindowEnv;
  1422.         fprint (fh, "    {%s, %ld},\n", wintags[tv], td);
  1423.     }
  1424.     else if ((tv >= GTVI_NewWindow) && (tv <= GTSC_Overlap))
  1425.     {
  1426.         tv -= GTVI_NewWindow;
  1427.         fprint (fh, "    {%s, %ld},\n", gadtool1[tv], td);
  1428.     }
  1429.     else if ((tv >= GTSL_Min) && (tv <= GTMX_Spacing))
  1430.     {
  1431.         tv -= GTSL_Min;
  1432.         fprint (fh, "    {%s, %ld},\n", gadtool2[tv], td);
  1433.     }
  1434.     else if ((tv >= CGTA_reserved1) && (tv <= CGTA_List))
  1435.     {
  1436.         tv -= CGTA_reserved1;
  1437.         fprint (fh, "    {%s, %ld},\n", appobject1[tv], td);
  1438.     }
  1439.     else if ((tv >= CGTA_Increment) && (tv <= CGTA_Decrement))
  1440.     {
  1441.         tv -= CGTA_Increment;
  1442.         fprint (fh, "    {%s, %ld},\n", appobject2[tv], td);
  1443.     }
  1444.     else if ((tv >= CGTA_LabelInfo) && (tv <= CGTA_InBorder))
  1445.     {
  1446.         tv -= CGTA_LabelInfo;
  1447.         fprint (fh, "    {%s, %ld},\n", appobject3[tv], td);
  1448.     }
  1449.     else if ((tv >= GA_LEFT) && (tv <= GA_LABELIMAGE))
  1450.     {
  1451.         tv -= GA_LEFT;
  1452.         fprint (fh, "    {%s, %ld},\n", intui1[tv], td);
  1453.     }
  1454.     else if ((tv >= PGA_FREEDOM) && (tv <= PGA_TOP))
  1455.     {
  1456.         tv -= PGA_FREEDOM;
  1457.         fprint (fh, "    {%s, %ld},\n", intui2[tv], td);
  1458.     }
  1459.     else if ((tv >= STRINGA_MaxChars) && (tv <= STRINGA_TextVal))
  1460.     {
  1461.         tv -= STRINGA_MaxChars;
  1462.         fprint (fh, "    {%s, %ld},\n", intui3[tv], td);
  1463.     }
  1464.     else if ((tv >= WA_Left) && (tv <= WA_GimmeZeroZero))
  1465.     {
  1466.         tv -= WA_Left;
  1467.         fprint (fh, "    {%s, %ld},\n", intui4[tv], td);
  1468.     }
  1469.     else if (tv == APSH_ObjIDHold)
  1470.     {
  1471.         /* Don't print anything for this one. */
  1472.     }
  1473.     else
  1474.     {
  1475.         fprint (fh, "    {0x%lx, %ld},\n", tv, td);
  1476.     }
  1477.     }
  1478.  
  1479.     fprint (fh, "    {TAG_DONE,}\n", NULL);
  1480. }
  1481.  
  1482. static BOOL anytags (struct TagItem * tl)
  1483. {
  1484.     struct TagItem *tags = tl;
  1485.     struct TagItem *tag;
  1486.     BOOL ret = FALSE;
  1487.     ULONG td, tv;
  1488.  
  1489.     if (tl)
  1490.     {
  1491.     while (tag = NextTagItem (&tags))
  1492.     {
  1493.         td = tag->ti_Data;
  1494.         tv = tag->ti_Tag;
  1495.  
  1496.         if (tv == APSH_GTFlags)
  1497.         {
  1498.         if (td)
  1499.         {
  1500.             ret = TRUE;
  1501.         }
  1502.         }
  1503.         else if ((tv == TAG_DONE) || (tv == APSH_ObjIDHold))
  1504.         {
  1505.         }
  1506.         else
  1507.         {
  1508.         ret = TRUE;
  1509.         }
  1510.     }
  1511.     }
  1512.  
  1513.     return (ret);
  1514. }
  1515.  
  1516. static VOID dumptagdata (struct ObjectNode * on, ULONG cnt, struct DumpRec * dr)
  1517. {
  1518.  
  1519.     if (on)
  1520.     {
  1521.     struct Object *o = &(on->on_Object);
  1522.     BPTR fh = dr->dr_FH;
  1523.  
  1524.     /* Do we have tags? */
  1525.     if (anytags (on->on_OTags))
  1526.     {
  1527.         /* Dump the tags */
  1528.         printtagdata (fh, o->o_Name, o->o_Type, on->on_OTags);
  1529.     }
  1530.     }
  1531. }
  1532.  
  1533. static VOID dumptags (struct ObjectNode * on, ULONG cnt, struct DumpRec * dr)
  1534. {
  1535.  
  1536.     if (on)
  1537.     {
  1538.     struct Object *o = &(on->on_Object);
  1539.     BPTR fh = dr->dr_FH;
  1540.  
  1541.     /* Do we have tags? */
  1542.     if (anytags (on->on_OTags))
  1543.     {
  1544.         /* Dump the tags */
  1545.         fprint (fh, "static struct TagItem %s_tags[] =\n", o->o_Name);
  1546.         fprint (fh, "{\n", NULL);
  1547.         printtags (fh, o->o_Name, o->o_Type, on->on_OTags);
  1548.         fprint (fh, "};\n\n", NULL);
  1549.     }
  1550.     }
  1551. }
  1552.  
  1553. /* This is a lot like FindTextEntry() */
  1554. static struct FuncsNode *FindFuncsNode (struct List * list, ULONG id)
  1555. {
  1556.     struct Node *node, *nxtnode;
  1557.     struct FuncsNode *fn;
  1558.     struct Funcs *fe;
  1559.     ULONG cnt = 0L;
  1560.  
  1561.     if (list && id)
  1562.     {
  1563.     /* Make sure there are entries in the list */
  1564.     if (list->lh_TailPred != (struct Node *) list)
  1565.     {
  1566.         /* Let's start at the very beginning... */
  1567.         node = list->lh_Head;
  1568.  
  1569.         /* Continue while there are still nodes */
  1570.         while (nxtnode = node->ln_Succ)
  1571.         {
  1572.         fn = (struct FuncsNode *) node;
  1573.         fe = &(fn->fn_Func);
  1574.  
  1575.         if (fe->fe_ID == id)
  1576.         {
  1577.             return (fn);
  1578.         }
  1579.  
  1580.         /* Go on to the next node */
  1581.         node = nxtnode;
  1582.         cnt++;
  1583.         }
  1584.     }
  1585.     }
  1586.  
  1587.     return (NULL);
  1588. }
  1589.  
  1590. static VOID dumpobject (struct ObjectNode * on, ULONG cnt, struct DumpRec * dr)
  1591. {
  1592.  
  1593.     if (on)
  1594.     {
  1595.     struct ObjectInfo *oi = dr->dr_OI;
  1596.     struct List *list = (struct List *) oi->oi_UserData;
  1597.     struct FuncsNode *fn;
  1598.     struct Object *o = &(on->on_Object);
  1599.     struct IBox *b = &(on->on_OBox);
  1600.     BPTR fh = dr->dr_FH;
  1601.     static ULONG textid;
  1602.     STRPTR name = NULL;
  1603.     LONG id;
  1604.  
  1605.     if (cnt == 0)
  1606.     {
  1607.         fprint (fh, "struct Object %s[] =\n", dr->dr_BaseName);
  1608.         fprint (fh, "{\n", NULL);
  1609.         textid = 0L;
  1610.     }
  1611.  
  1612.     /* Is there an object after this one? */
  1613.     if (o->o_NextObject)
  1614.     {
  1615.         fprint (fh, "    {&%s[%ld], ", dr->dr_BaseName, (cnt + 1L));
  1616.     }
  1617.     else
  1618.     {
  1619.         fprint (fh, "    {NULL,   ", NULL);
  1620.     }
  1621.  
  1622.     fprint (fh, "%ld, %ld, ",
  1623.         (LONG) o->o_Group, (LONG) o->o_Priority);
  1624.  
  1625.     /* Print the #define name of the object */
  1626.     {
  1627.         if ((o->o_Type >= 1) && (o->o_Type <= 14))
  1628.         {
  1629.         name = objname1[(o->o_Type - 1)];
  1630.         }
  1631.         else if ((o->o_Type >= 30) && (o->o_Type <= 38))
  1632.         {
  1633.         name = objname2[(o->o_Type - 30)];
  1634.         }
  1635.         else if ((o->o_Type >= 50) && (o->o_Type <= 50))
  1636.         {
  1637.         name = objname3[(o->o_Type - 50)];
  1638.         }
  1639.         else if ((o->o_Type >= 60) && (o->o_Type <= 64))
  1640.         {
  1641.         name = objname4[(o->o_Type - 60)];
  1642.         }
  1643.         else if ((o->o_Type >= 70) && (o->o_Type <= 77))
  1644.         {
  1645.         name = objname5[(o->o_Type - 70)];
  1646.         }
  1647.  
  1648.         if (name)
  1649.         {
  1650.         fprint (fh, "%s, ", name);
  1651.         }
  1652.         else
  1653.         {
  1654.         fprint (fh, "NULL, ");
  1655.         }
  1656.     }
  1657.  
  1658.     id = GetTagData (APSH_ObjIDHold, NULL, o->o_Tags);
  1659.     if ((fn = FindFuncsNode (list, id)) &&
  1660.         (name = fn->fn_Func.fe_Name) &&
  1661.         (strlen(name) > 0))
  1662.     {
  1663.         fprint (fh, "%sID, ", fn->fn_Func.fe_Name);
  1664.     }
  1665.     else
  1666.     {
  1667.         fprint (fh, "NULL, ", NULL);
  1668.     }
  1669.  
  1670.     if (o->o_Flags)
  1671.     {
  1672.         parseFlags (fh, (ULONG) o->o_Flags, &ObjectFlags[0], "", ", ");
  1673.     }
  1674.     else
  1675.     {
  1676.         fprint (fh, "NULL, ", NULL);
  1677.     }
  1678.  
  1679.     if (o->o_Key)
  1680.     {
  1681.         fprint (fh, "'%lc', ", (LONG) o->o_Key);
  1682.     }
  1683.     else
  1684.     {
  1685.         fprint (fh, "NULL, ", NULL);
  1686.     }
  1687.  
  1688.     if (o->o_Name)
  1689.     {
  1690.         fprint (fh, "\"%s\", ", o->o_Name);
  1691.     }
  1692.     else
  1693.     {
  1694.         fprint (fh, "NULL, ", NULL);
  1695.     }
  1696.  
  1697.     if (o->o_LabelID)
  1698.     {
  1699.         textid++;
  1700.         fprint (fh, "%ldL,\n", textid);
  1701.     }
  1702.     else
  1703.     {
  1704.         fprint (fh, "NULL,\n", NULL);
  1705.     }
  1706.  
  1707.     /* Line 2 */
  1708.     fprint (fh, "     {%ld, %ld, %ld, %ld}, ",
  1709.         (LONG) b->Left, (LONG) b->Top, (LONG) b->Width, (LONG) b->Height);
  1710.  
  1711.     /* Do we have tags? */
  1712.     if (anytags (on->on_OTags))
  1713.     {
  1714.         /* Dump the tags */
  1715.         fprint (fh, "%s_tags, ", o->o_Name);
  1716.     }
  1717.  
  1718.     /* Is there an object after this one? */
  1719.     if (o->o_NextObject == NULL)
  1720.     {
  1721.         /* End the line */
  1722.         fprint (fh, "},\n", NULL);
  1723.  
  1724.         /* End of the array */
  1725.         fprint (fh, "};\n\n", NULL);
  1726.     }
  1727.     else
  1728.     {
  1729.         /* End the line */
  1730.         fprint (fh, "},\n", NULL);
  1731.  
  1732.         /* Get an extra blank in there... */
  1733.         if (o->o_Type == OBJ_Window)
  1734.         {
  1735.         fprint (fh, "\n", NULL);
  1736.         }
  1737.     }
  1738.     }
  1739. }
  1740.